package com.mvvm.start.common.mvvm.v.dialog

import android.content.Context
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import com.mvvm.start.base.base.BaseDialog
import com.mvvm.start.common.bean.DefaltBean
import com.mvvm.start.common.databinding.DefaltDialogBinding


/**
 * @author
 * @功能:默认风格的dialog
 * @Creat 12/11/20 1:42 PM
 * @Compony 465008238@qq.com
 */
/*
DefaltDialog(this).apply {
            setCancelable(false)
            setDefaltBean { defaltBean.apply { message = "还没有保存哦,确定退出吗？" } }
            setCancelAndSureClick({ dismiss() }) {
                dismiss()
                finish()
            }
        }
*/

class DefaltDialog(context: Context) : BaseDialog<DefaltDialogBinding>(context) {
    fun setDefaltBean(block: () -> DefaltBean) {
        viewBinding.defaltBean = block()
    }
    fun setCancelAndSureClick(cancelBlock: () -> Unit, sureBlock: () -> Unit) {
        viewBinding.tvSure.setOnClickListener {
            sureBlock()
        }
        viewBinding.tvCancel.setOnClickListener {
            cancelBlock()
        }
    }
    override fun dismiss() {
        super.dismiss()
    }
    override fun initWindow(window: Window) {
        val dialogParams: WindowManager.LayoutParams = window!!.attributes
        dialogParams.apply {
            width = WindowManager.LayoutParams.WRAP_CONTENT
            height = WindowManager.LayoutParams.WRAP_CONTENT
            //设置底部显示
            gravity = Gravity.CENTER
//            windowAnimations = R.style.DefaltDialog_Animation
        }
        window!!.attributes = dialogParams
    }

    override fun canCancel() = false

    override fun initView() {
    }

    override fun initData() {
    }
}

